package com.analyse.stock.enums;

import org.apache.commons.lang3.StringUtils;

public enum  MarketEnum {
    XSHE("0","SZ","深圳证券市场A"),
    XSHEB("0","SZ","深圳证券交易所（B股）"),
    XSHG("1","SH","上海证券市场"),
    XSHGB("1","SH","上海证券交易所（B股）"),
    BJSE("0","BJ","北京证券市场")
            ;
    MarketEnum(String code,String shortMarkCode, String desc) {
        this.code = code;
        this.desc = desc;
        this.shortMarkCode = shortMarkCode;
    }

    private final String code;
    private final String shortMarkCode;
    private final String desc;

    public String getCode() {
        return this.code;
    }
    public String getShortMarkCode() {
        return this.shortMarkCode;
    }

    public String getName() {
        return this.desc;
    }

    public String getDesc() {
        return desc;
    }

    public static String getDescByCode(String code){
        if(StringUtils.isBlank(code)) {
            return StringUtils.EMPTY;
        }
        for (MarketEnum anEnum : values()) {
            if (anEnum.getCode().equalsIgnoreCase(code)){
                return anEnum.getDesc();
            }
        }
        return StringUtils.EMPTY;
    }

    public static String getByName(String name){
        if(StringUtils.isBlank(name)) {
            return StringUtils.EMPTY;
        }
        for (MarketEnum anEnum : values()) {
            if (anEnum.name().contains(name.toUpperCase())){
                return anEnum.getCode();
            }
        }
        return StringUtils.EMPTY;
    }
}
